#deck class
from card import Card
class Deck(object):
    def __init__(self,deckName,contents=None):
        self.cards=contents
        if contents==None: self.cards=[]
        self.deckName = deckName
    def __str__(self):
        return self.__repr__()
    def __repr__(self):
        #return "(%s) Deck contains (%s)"%(self.deckName,self.cards)
        return "Deck(\"%s\",%s)"%(self.deckName,self.cards)
    def append(self, card):
        self.cards.append(card)

    def __len__(self):
        return len(self.cards)

    def pop(self, index):
        """ pop the card (and return it) from the given index"""
        try:
            return self.cards.pop(index)
        except IndexError:
            print "SERIOUS ERROR."
            print "Asked to pop", index
            print "Len cards:", len(self.cards)

    def __contains__(self,card):
        #print "Deck asked to check %s"%card
        for i in self.cards:
         #   print "Is it %s?"%(i.code),
            if i.code==card:
          #      print "Yes!"
                return True
            else:
                pass
           #     print "No:("
        return False

    def remove (self,card):
        forRemoval = None
        for i in self.cards:
            if i.code==card:
                forRemoval=i
                break
        if forRemoval!=None:
            self.cards.remove(forRemoval)
            return forRemoval
        else:
            raise ValueError("Card cannot be removed - not in deck")
            

#create the object for a single deck, then call each object for
#S_deck, H_deck and A_deck

if __name__ == "__main__":
    c=Card("a","a card", "A/A1","A1.png")
    deck = Deck( "Hazard")
    deck.append(c)
    print deck
    d2=eval(deck.__repr__())
    print d2

   
